package com.jacky.serial;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;

public class Student implements Serializable {
    private static final long serialVersionUID = -2496216477944789122L;
    private String name;
    private transient int age;
    private transient String password;

    private void readObject( ObjectInputStream objectInputStream ) throws IOException, ClassNotFoundException {

        // 调用默认的反序列化函数
        objectInputStream.defaultReadObject();

        // 手工检查反序列化后学生成绩的有效性，若发现有问题，即终止操作！
        if( 0 > age || 100 < age ) {
            throw new IllegalArgumentException("年龄只能在0到100之间！");
        }
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

//    @Override
//    public String toString() {
//        toString();
//        return "Student{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                ", password='" + password + '\'' +
//                '}';
//    }
}
